import 'package:flutter_admin/pages/common/cry/cry_all.dart';
import 'package:flutter_admin/pages/common/cry/vo/select_option_vo.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_admin/pages/common/cry/cry_button.dart';
import 'package:flutter_admin/api/odoo/dynamic_data_api.dart';
import 'package:flutter_admin/constants/constant.dart';
import 'package:flutter_admin/models/odoo/dms_documentlocation.dart';
import 'package:flutter_admin/utils/store_util.dart';
import '../../../generated/l10n.dart';

class DmsDocumentlocationDialog extends StatefulWidget {
  DmsDocumentlocationDialog();

  @override
  _DmsDocumentlocationDialogState createState() => _DmsDocumentlocationDialogState();
}

class _DmsDocumentlocationDialogState extends State<DmsDocumentlocationDialog> {

  // late List<Widget> children;
  final GlobalKey<FormState> formKey = GlobalKey<FormState>();

  DmsDocumentlocation  dmsDocumentlocation = DmsDocumentlocation();

   //所属区域
  List<SelectOptionVO> areaList = [];

  @override
  void initState() {
    super.initState();
    _loadData();
  }

  _loadData() async{
    //所属区域
    areaList = await DynamicDataApi.getModelSelect(active: false,model: "dms.documentarea",name: "areaname");
    setState(() { });
  }
  @override
  Widget build(BuildContext context) {
    var form = Form(
      key: formKey,
      child: Wrap(
        children: <Widget>[
          CrySelect(
            label: '档案区域',
            dataList: areaList,
            value: dmsDocumentlocation.areaId,
            onSaved: (v) => { dmsDocumentlocation.areaId = v},
          ),
          CryInput(
            width: 400,
            label: '位置编码',
            value: dmsDocumentlocation.locationcode,
            onSaved: (v) {
              dmsDocumentlocation.locationcode = v;
            },
          ),
          CryInput(
            width: 400,
            label: '位置名称',
            value: dmsDocumentlocation.locationname,
            onSaved: (v) {
              dmsDocumentlocation.locationname = v;
            },
          ),
        ],
      ),
    );
    var buttonBar = ButtonBar(
      alignment: MainAxisAlignment.center,
      children: <Widget>[
        CryButton(
          label: "确定",
          onPressed: () {
            FormState form = formKey.currentState!;
            form.save();
            Navigator.pop(context, dmsDocumentlocation);
          },
          iconData: Icons.save,
        ),
        CryButton(
          label: S.of(context).cancel,
          onPressed: () {
            Navigator.pop(context);
          },
          iconData: Icons.cancel,
        )
      ],
    );
    var result = Scaffold(
      appBar: AppBar(
        title: Text("查询"),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [form],
        ),
      ),
      bottomNavigationBar: buttonBar,
    );
    return SizedBox(
      width: 650,
      height: 650,
      child: result,
    );
    // return result;
  }
}